
#include "tiletype.h"

#include "exceptions.h"

TileTypeProperties::TileTypeProperties() : name("Undefined"), protection(0), slow(0)
{
    fillPracticability(0);  //not practicable
}

void TileTypeProperties::fillPracticability(quint8 n)
{
    for(unsigned int i = 0 ; i < unitTypeNumber ; i++)
    {
        practicability[i] = n;
    }
}

TileTypeFactory& TileTypeFactory::getInstance()
{
    static TileTypeFactory instance;
    return instance;
}

TileTypeProperties TileTypeFactory::getTileProperties(TileType type) const
{
    if((quint8)type >= m_typesNb)
        throw EX_OUT_OF_RANGE(m_typesNb, (quint32)type);
    else
        return m_types[type];
}

quint8 TileTypeFactory::getPracticability(TileType tileType, UnitType unitType) const
{
    return m_types[tileType].practicability[unitType];
}

TileTypeFactory::TileTypeFactory() : m_typesNb(8)
{
    m_types[HOLE].name = "Hole";
    m_types[HOLE].practicability[AERIAL] = 1;
    m_types[HOLE].practicability[IMMATERIAL] = 3;

    m_types[WALL].name = "Wall";
    m_types[WALL].protection = 25;
    m_types[WALL].slow = 50;
    m_types[WALL].practicability[AERIAL] = 1;
    m_types[WALL].practicability[IMMATERIAL] = 1;
    m_types[WALL].practicability[PLANT] = 2;

    m_types[PLAIN].name = "Plain";
    m_types[PLAIN].slow = 5;
    m_types[PLAIN].fillPracticability(1);
    m_types[PLAIN].practicability[AQUATIC] = 0;

    m_types[WATER].name = "Water";
    m_types[WATER].slow = 50;
    m_types[WATER].practicability[AQUATIC] = 1;
    m_types[WATER].practicability[AMPHIBIAN] = 1;
    m_types[WATER].practicability[AERIAL] = 1;
    m_types[WATER].practicability[IMMATERIAL] = 1;

    m_types[MOUNTAIN].name = "Mountain";
    m_types[MOUNTAIN].slow = 67;
    m_types[MOUNTAIN].practicability[IMMATERIAL] = 1;

    m_types[SAND].name = "Sand";
    m_types[SAND].slow = 67;
    m_types[SAND].practicability[GROUND] = 3;
    m_types[SAND].practicability[AERIAL] = 1;
    m_types[SAND].practicability[MOUNTED] = 3;
    m_types[SAND].practicability[IMMATERIAL] = 1;

    m_types[FOREST].name = "Forest";
    m_types[FOREST].protection = 25;
    m_types[FOREST].slow = 50;
    m_types[FOREST].fillPracticability(1);
    m_types[FOREST].practicability[GROUND] = 2;
    m_types[FOREST].practicability[AQUATIC] = 0;
    m_types[FOREST].practicability[AMPHIBIAN] = 3;
    m_types[FOREST].practicability[MOUNTED] = 2;

    m_types[SWAMP].name = "Swamp";
    m_types[SWAMP].protection = 10;
    m_types[SWAMP].slow = 75;
    m_types[SWAMP].fillPracticability(1);
    m_types[SWAMP].practicability[GROUND] = 0;
    m_types[SWAMP].practicability[AQUATIC] = 2;
    m_types[SWAMP].practicability[AMPHIBIAN] = 2;
    m_types[SWAMP].practicability[MOUNTED] = 3;
}
